package drawable
{
	import flash.display.MovieClip;
	import flash.display.Shape;
	import flash.display.Sprite;
	

	public class Drawable extends Sprite implements  IDrawable, IField
	{
		
		private var _field:Field;
		private var _drawData:Array ;
		
		private var _itColor:uint;
		private var _lineWidth:Number = 1.5; 
		
		public function Drawable()
		{
			super();
			_field = new Field();
			_field.draw();
			this.addChild( _field );
		}

		public function get step():int{return _field.step ;}
		public function set step(_s:int):void{
			_field.step = _s;
			_field.draw();
		}
		public function get zero():IPoint{ return _field.zero }
		
		/**
		 * квадрат же
		 * */
		public function set size( value:int ):void{
			_field.size = value;
			_field.draw();
		}
		
		public function get size(  ):int{
			return _field.size;
		}
		
		public function set drawData( data:Array ):void{
			this._drawData = data;
		}
		
		public function get itColor():uint{
			return this._itColor;
		}
		public function set lineWidth(w:Number):void{
			this._lineWidth = w;
		}
		
		/**
		 * Point data:Array
		 * */
		public function draw( ):void{
			_itColor = Math.random() * 0xFFFFFF;
			var i:int = 0;
			graphics.lineStyle(_lineWidth, (_itColor), 1);
			while( this._drawData.length > 0 ){
				var _point:IPoint = this._drawData.shift();
				var _x:Number = _field.zero.x   + (_point.x*_field.step);
				var _y:Number = _field.zero.y - (_point.y*_field.step);
				if( i == 0 ){
					graphics.moveTo( _x , _y );
					i++;
				}else{
					graphics.curveTo(_x , _y, _x , _y )
				}
			}
		}
		
		public function clear():void{
			this.graphics.clear();
			graphics.clear();
		}
		
	}
}